package cn.fintecher.pangolin.service.manage.web;

import cn.fintecher.pangolin.common.web.BaseController;
import cn.fintecher.pangolin.entity.elastic.SensitiveWord;
import cn.fintecher.pangolin.service.manage.request.AddSensitiveWordRequest;
import cn.fintecher.pangolin.service.manage.request.FindSensitiveWordRequest;
import cn.fintecher.pangolin.service.manage.request.ModifySensitiveWordRequest;
import cn.fintecher.pangolin.service.manage.response.PrincipalResponse;
import cn.fintecher.pangolin.service.manage.service.SensitiveWordService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 敏感词相关接口
 * @Date: 9:36 2019/9/29
 */

@RestController
@RequestMapping("/api/sensitiveWordController")
@Api(value = "敏感词相关接口", description = "敏感词相关接口")
public class SensitiveWordController extends BaseController {
    @Autowired
    private SensitiveWordService sensitiveWordService;

    /**
     * 查询全部敏感词
     */
    @ApiOperation(value = "查询全部敏感词", notes = "查询全部敏感词")
    @GetMapping("/findAllSensitiveWord")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query", value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query", value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<SensitiveWord>> findAllSensitiveWord(FindSensitiveWordRequest request, Pageable pageable,
                                                                    @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request to find all sensitive word,{}", request);
        Page<SensitiveWord> page = sensitiveWordService.findAllSensitiveWord(request, pageable, token);
        return ResponseEntity.ok().body(page);
    }

    /**
     * 新增敏感词
     */
    @ApiOperation(value = "新增敏感词", notes = "新增敏感词")
    @PostMapping("/addSensitiveWord")
    public ResponseEntity<Void> addSensitiveWord(@RequestBody AddSensitiveWordRequest request,
                                                 @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request add sensitive word,{}", request);
        sensitiveWordService.addSensitiveWord(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改敏感词
     */
    @ApiOperation(value = "修改敏感词", notes = "修改敏感词")
    @PutMapping("/modifySensitiveWord")
    public ResponseEntity<Void> modifySensitiveWord(@RequestBody ModifySensitiveWordRequest request,
                                                    @RequestHeader(value = "X-UserToken") String token) {
        log.info("REST request modify sensitive word,{}", request);
        sensitiveWordService.modifySensitiveWord(request, token);
        return ResponseEntity.ok().build();
    }

    /**
     * 删除敏感词
     */
    @ApiOperation(value = "删除敏感词", notes = "删除敏感词")
    @DeleteMapping("/deleteSensitiveWord")
    public ResponseEntity<Void> deleteSensitiveWord(@RequestParam @ApiParam(value = "主键ID", required = true) String id) {
        log.info("REST request to delete sensitive word,{}", id);
        sensitiveWordService.deleteSensitiveWord(id);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询未配置敏感词的委托方
     */
    @ApiOperation(value = "查询未配置敏感词的委托方", notes = "查询未配置敏感词的委托方")
    @GetMapping("/getPrincipalNoWordConfig")
    public ResponseEntity<List<PrincipalResponse>> getPrincipalNoWordConfig() {
        log.info("REST request to get principal no word config");
        List<PrincipalResponse> list = sensitiveWordService.getPrincipalNoWordConfig();
        return ResponseEntity.ok().body(list);
    }
}
